﻿
//------------地图管理--------------------------------------------
//释放地图资源
this.unloadMap = function () {
    //    if (googleMap != null) googleMap.unload();
    //    if (jmMap != null) jmMap.unload();
}

function formatDateTime(value) {
    var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
    var reTime = /\d{2}:\d{2}:\d{2}/gi;
    return value.match(reDate) + " " + value.match(reTime);
}
function renderDate(value) {
    var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
    var reTime = /\d{2}:\d{2}:\d{2}/gi;
    return value.match(reDate) + " " + value.match(reTime);
}
function renderDateT(value) {
    var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
    var reTime = /\d{2}:\d{2}:\d{2}/gi;
    if (value.match(reDate) == null)
        return ''
    else
        return value.match(reDate) + " " + value.match(reTime);
}
function GetFlag(value) {
    var ret = "未知";
    switch (value) {
        case '0':
            ret = "未确认";
            break;
        case '1':
            ret = "已确认";
            break;
        default:
            ret = "未知";
            break;
    }
    return ret;
}
function GetAlarmTypeString(value) {
    if (currentService == 5) {
        return value;
    }
//    车最后定的是1：超速，2：停留，3：出区域
    if (currentService == 1 || currentService == 3) {

        var ret = "未定义报警类型";
        switch (value) {
            case '1':
                ret = "超速报警";
                break;
            case '2':
                ret = "停留报警";
                break;
            case '3':
                ret = "出区域报警";
                break;
            default:
                ret = "未定义报警类型";
                break;
        }
        return ret;
    }
//    人里面1是SOS，3是停留，4是出区域，6是多终端（聚集），10是开机，11是关机，12是低电平
    return value;
}
function getTemperatureRT(value) {
    return value + "°";
}
function getStatusName(value) {
    var ret = "未知";
    switch (value) {
        case '0':
            ret = "正常行驶";
            break;
        case '2':
            ret = "紧急报警";
            break;
        case '3':
            ret = "电子围栏报警";
            break;
        case '6':
            ret = "离线";
            break;
        case '7':
            ret = "油耗报警";
            break;
        case '41':
            ret = "出河西区报警";
            break;
        case '101':
        case '102':
        case '103':
            ret = "GPS天线报警";
            break;
        case '110':
            ret = "停留报警";
            break;
        case '111':
            ret = "进区域报警";
            break;
        case '112':
            ret = "出区域报警";
            break;
        default:
            ret = "未知";
            break;
    }
    return ret;
}
function getDirectionName(value) {
    var valueName = "北";
    if (value < 22.5 && value >= 0) {
        valueName = "北";
    }
    else if (value >= 22.5 && value < 67.5) {
        valueName = "东北";
    }
    else if (value >= 67.5 && value < 112.5) {
        valueName = "东";
    }
    else if (value >= 112.5 && value < 157.5) {
        valueName = "东南";
    }
    else if (value >= 157.5 && value < 200.5) {
        valueName = "南";
    }
    else if (value >= 200.5 && value < 245.5) {
        ret = "05";
        valueName = "西南";
    }
    else if (value >= 245.5 && value < 292.5) {
        valueName = "西";
    }
    else if (value >= 292.5 && value < 337.5) {
        valueName = "西北";
    }
    else if (value >= 337.5 && value <= 360) {
        valueName = "北";
    }
    return valueName;
}

function getDirectionIconName(value) {
    var valueName = "car0.gif";
    if (value < 22.5 && value >= 0) {
        valueName = "car0.gif";
    }
    else if (value >= 22.5 && value < 67.5) {
        valueName = "car1.gif";
    }
    else if (value >= 67.5 && value < 112.5) {
        valueName = "car2.gif";
    }
    else if (value >= 112.5 && value < 157.5) {
        valueName = "car3.gif";
    }
    else if (value >= 157.5 && value < 200.5) {
        valueName = "car4.gif";
    }
    else if (value >= 200.5 && value < 245.5) {
        valueName = "car5.gif";
    }
    else if (value >= 245.5 && value < 292.5) {
        valueName = "car6.gif";
    }
    else if (value >= 292.5 && value < 337.5) {
        valueName = "car7.gif";
    }
    else if (value >= 337.5 && value <= 360) {
        valueName = "car0.gif";
    }
    return valueName;
}

function getDirectionIconNameWithType(value, type) {
    var valueName = "car0.gif";
    if (value < 22.5 && value >= 0) {
        valueName = "car0.gif";
    }
    else if (value >= 22.5 && value < 67.5) {
        valueName = "car1.gif";
    }
    else if (value >= 67.5 && value < 112.5) {
        valueName = "car2.gif";
    }
    else if (value >= 112.5 && value < 157.5) {
        valueName = "car3.gif";
    }
    else if (value >= 157.5 && value < 200.5) {
        valueName = "car4.gif";
    }
    else if (value >= 200.5 && value < 245.5) {
        valueName = "car5.gif";
    }
    else if (value >= 245.5 && value < 292.5) {
        valueName = "car6.gif";
    }
    else if (value >= 292.5 && value < 337.5) {
        valueName = "car7.gif";
    }
    else if (value >= 337.5 && value <= 360) {
        valueName = "car0.gif";
    }
    return type + "/" + valueName;
}

function returnSetting() {
    Ext.MessageBox.prompt("回传频率设置", "请输入回传频率(单位秒):", function (button, text) {
        if (button == "ok" && text != "") {
            try {
                if (parseInt(text) >= 5 || parseInt(text) <= 99) {
                    if (curVID != 0) {
                        Ext.Ajax.request({
                            url: './Json/SendCommand.ashx',
                            params: {
                                cardNo: curCardNo, msg: '001,' + text
                            },
                            success: function (response, options) {
                                Ext.Msg.alert('信息!', '提交成功');
                            },
                            failure: function () {
                                Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
                            }
                        });
                    }
                }
                else
                    Ext.Msg.alert("提示", "回传频率只能在5秒和99秒之间");
            } catch (e) { Ext.Msg.alert('信息!', e); ; }


        }
    }, null, null, '30');
}

function speedSetting() {
    Ext.MessageBox.prompt("速度限制设置", "请输入限制速度(单位公里/小时),0为取消限制:", function (button, text) {
        if (button == "ok" && text != "") {
            try {
                if (parseInt(text) <= 200) {
                    if (curVID != 0) {
                        var cmdCode = '013,';
                        if (parseInt(text) == 0)
                            cmdCode = '014,';
                        Ext.Ajax.request({
                            url: './Json/SendCommand.ashx',
                            params: {
                                cardNo: curCardNo, msg: cmdCode + text
                            },
                            success: function (response, options) {
                                Ext.Msg.alert('信息!', '提交成功');
                            },
                            failure: function () {
                                Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
                            }
                        });
                    }
                }
                else
                    Ext.Msg.alert("提示", "速度限制值只能为200以内");
            } catch (e) { Ext.Msg.alert('信息!', e); ; }
        }
    }, null, null, '100');
}

function returnPosition1() {

}
function returnPosition2() {

}
function returnPosition3() {

}
function returnPosition() {
    Ext.Ajax.request({
        //url: './Services/CommonService.asmx/SendMessage',
        url: './Json/SendCommand.ashx',
        params: {
            cardNo: curCardNo, msg: '003,111'
        },
        success: function (response, options) {
            Ext.Msg.alert('信息!', '提交成功');
        },
        failure: function () {
            Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
        }
    });
}



function setRectangle(cmd) {
    Ext.Ajax.request({
        //url: './Services/CommonService.asmx/SendMessage',
        url: './Json/SendCommand.ashx',
        params: {
            cardNo: curCardNo, msg: cmd
        },
        success: function (response, options) {
            Ext.Msg.alert('信息!', '提交成功');
        },
        failure: function () {
            Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
        }
    });
}

function cancelRectangle() {
    Ext.Ajax.request({
        //url: './Services/CommonService.asmx/SendMessage',
        url: './Json/SendCommand.ashx',
        params: {
            cardNo: curCardNo, msg: '011'
        },
        success: function (response, options) {
            Ext.Msg.alert('信息!', '提交成功');
        },
        failure: function () {
            Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
        }
    });
}


function theCarVideo() {
    console.log(curCardNo);
    //alert(curCardNo);
    var videoInfo = Ext.data.Record.create([{ name: 'ICCID' }]);
    // 数据源
    var videoInfo = new Ext.data.Store({
        url: "./Json/JsonGetVehicleCurrentInfoList.ashx",
        autoSync: false,
        reader: new Ext.data.JsonReader({ root: 'data' }, videoInfo)
    });

//    videoInfo.load({
//        params: { carNum: curCardNo, op: 'GetVideoBySimcard_No' }, //2019.09.20 zx
//        autoLoad: true,
//        callback: function (records, options, success) {
//            if (records.length > 0) {
                var window = new Ext.Window({
                    title: "实时监控视频",
                    layout: 'fit',       //弹出窗口内布局会充满整个窗口;
                    width: 680,          //设置窗口大小;
                    height: 540,
                    //items: tabPanel         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
                    items: [
                        {
                            html: '<iframe src="http://111.160.78.62:88/808gps/open/player/video.html?lang=zh&account=glqa&password=glqa&devIdno=' + curCardNo + '" width="100%" height="100%"></iframe>'
                            //html: '<iframe src="./html/TheCarVideo.html?lang=zh&devIdno=' + '015620509715' + '" width="100%" height="100%"></iframe>'
                            //html: '<iframe src="./html/TheCarVideoByNP.html?lang=zh&account=admin&password=admin&devIdno=' + '015620509715' + '" width="100%" height="100%"></iframe>'
                        }
                    ]
                });
                window.show();
//            } else {
//                alert("此车暂不提供视频服务");
//            }
//        }
//    });

}

function openAllCarVideo() {
    window.open("http://111.160.78.62:88/808gps/index.html?account=admin&password=admin&clientLogin=2");
}

function loginout() {
    window.location = 'selectOptions.aspx';
//    Ext.MessageBox.confirm('系统提示', '你确定要注销吗?', function (btn) {
//        if (btn == 'yes') {
//            Ext.Ajax.request({
//                url: './Services/loginout.aspx',
//                success: function (request) {
//                    Ext.Msg.alert('注销成功!', '欢迎再次访问!', function (btn, text) {
//                        if (btn == 'ok') {
//                            var redirect = 
//                            window.location = redirect;
//                        }
//                    });

//                },
//                failure: function () {
//                    Ext.Msg.alert('注销失败!', '请重新尝试');
//                }
//            });
//        }
//    });

}

function changPassword() {
    var changPwd = new Ext.FormPanel(
        {
            frame: true,
            defaultType: "textfield",

            labelWidth: 75,
            frame: true,
            //title : '修改密码',
            width: 250,
            waitMsgTarget: true,
            items: [{

                fieldLabel: "新密码",
                name: "loginUsername",
                allowBlank: false

                //                    inputType: 'password',
                //                    //xtype: 'textfield',
                //                    fieldLabel: '新密码',
                //                    labelStyle: 'width:80px',
                //                    width: 150,
                //                    name: 'LoginPass',
                //                    allowBlank: false,
                //                    blankText: '请输入新密码'
            },
                {
                    name: 'LoginPassConfirm',
                    fieldLabel: "密  码",
                    inputType: "password",
                    allowBlank: false


                    //                    inputType: 'password',
                    //                    xtype: 'textfield',
                    //                    fieldLabel: '确认密码',
                    //                    labelStyle: 'width:80px',
                    //                    width: 150,
                    //                    name: 'LoginPassConfirm',
                    //                    allowBlank: false,
                    //                    blankText: '请输入确认密码',
                    //                    validator: checkPassword, //指定验证的方法
                    //                    invalidText: '新密码与确认密码不一致！'
                }
            ],
            buttons:
            [
                {
                    id: 'btnOk',
                    text: '确  定',
                    handler: function () {
                        //如果验证合法
                        if (changPwd.form.isValid()) {
                            setTimeout(function () { }, 10000);
                            //提交到服务器
                            changPwd.form.submit
                            (
                                {
                                    method: 'post', //提交方式为post
                                    url: "./Services/changpassword.aspx",
                                    waitTitle: "连接中...",
                                    waitMsg: "正在发送数据...",
                                    success: function (form, action) {
                                        Ext.MessageBox.alert('恭喜', '修改成功!');
                                        newWin.hide();
                                    },
                                    failure: function () {
                                        Ext.Msg.alert('错误', '服务器出现错误请稍后再试！');
                                    }
                                }
                            );
                        }
                    }

                },
                {
                    text: '取  消',
                    handler: function () {
                        newWin.hide();
                    }
                }
            ]
        }
    );


    //定义窗体
    newWin = new Ext.Window(
        {
            layout: 'fit',
            width: 270,
            height: 150,
            collapsible: true, //允许缩放条
            closeAction: 'hide',
            plain: true,
            modal: 'true', //启用遮罩
            title: '修改密码',
            items: changPwd
        }
    );
    //显示窗体
    newWin.show();
}

function checkPassword() {
    return Ext.get('LoginPassConfirm').dom.value == Ext.get('LoginPass').dom.value;
}


function dataFormat(date, fmt) { //author: meizz
    var o = {
        "M+": date.getMonth() + 1,                 //月份   
        "d+": date.getDate(),                    //日   
        "h+": date.getHours(),                   //小时   
        "m+": date.getMinutes(),                 //分   
        "s+": date.getSeconds(),                 //秒   
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
        "S": date.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}